import Vue from 'vue'
import Vuex from 'vuex'
import city from './city'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    username: JSON.parse(sessionStorage.getItem('uname')) || '',
    role: JSON.parse(sessionStorage.getItem('role')) || ''
  },
  mutations: {
    SAVE_UNAME(state, uname) {
      sessionStorage.setItem('uname', JSON.stringify(uname))
      state.username = uname
    },
    SAVE_ROLE(state, role) {
      sessionStorage.setItem('role', JSON.stringify(role))
      state.role = role
    },
    DEL_UNAME(state) {
      sessionStorage.removeItem('uname')
      state.username = ''
    },
    DEL_ROLE(state) {
      sessionStorage.removeItem('role')
      state.role = ''
    }
  },
  actions: {
    saveUname({ commit }, uname) {
      commit('SAVE_UNAME', uname)
    }

  },
  modules: {
    city
  }
})
